package kr.pe.johnkim.pushchat.mobile.dao;

import kr.pe.johnkim.pushchat.mobile.domain.PushChatDiary;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 7. 11.
 */
@Repository
public class PushChatDiaryDaoImpl extends SqlSessionDaoSupport implements PushChatDiaryDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PushChatDiaryDaoImpl.class);

    /**
     * 일기를 등록 한다.
     *
     * @param pushChatDiary
     */
    @Override
    public void registerDiary(PushChatDiary pushChatDiary) {
        logger.info("registerDiary");
        this.getSqlSession().insert("PUSHCHAT_DIRAY.registerDiary",pushChatDiary);
    }

    /**
     * 일기를 수정 한다.
     *
     * @param pushChatDiary
     */
    @Override
    public void updateDiary(PushChatDiary pushChatDiary) {
        logger.info("updateDiary");
        this.getSqlSession().update("PUSHCHAT_DIRAY.updateDiary", pushChatDiary);
    }

    /**
     * 일기를 비활성화 한다.
     *
     * @param pushChatDiary
     */
    @Override
    public void updateDeactivateDiary(PushChatDiary pushChatDiary) {
        logger.info("updateDeactivateDiary");
        this.getSqlSession().update("PUSHCHAT_DIRAY.updateDeactivateDiary", pushChatDiary);
    }

    /**
     * 일기 목록을 가져 온다.
     *
     * @param pushChatDiary
     * @return
     */
    @Override
    public List<PushChatDiary> selectDiaryList(PushChatDiary pushChatDiary) {
        logger.info("selectDiaryList");
        return this.getSqlSession().selectList("PUSHCHAT_FRIEND.selectDiaryList", pushChatDiary);
    }

    /**
     * 일기 상세 정보를 가져 온다.
     *
     * @param pushChatDiary
     * @return
     */
    @Override
    public PushChatDiary selectDiaryInformation(PushChatDiary pushChatDiary) {
        logger.info("selectDiaryInformation");
        return (PushChatDiary)this.getSqlSession().selectOne("PUSHCHAT_FRIEND.selectDiaryInformation", pushChatDiary);
    }

    /**
     * 내 일기 목록을 가져 온다.
     *
     * @param pushChatDiary
     * @return
     */
    @Override
    public List<PushChatDiary> selectMyDiaryList(PushChatDiary pushChatDiary) {
        logger.info("selectMyDiaryList");
        return this.getSqlSession().selectList("PUSHCHAT_FRIEND.selectMyDiaryList", pushChatDiary);
    }

    /**
     * 검색한 일기 목록을 가져 온다.
     *
     * @param pushChatDiary
     * @return
     */
    @Override
    public List<PushChatDiary> selectSearchDiaryList(PushChatDiary pushChatDiary) {
        logger.info("selectSearchDiaryList");

        return this.getSqlSession().selectList("PUSHCHAT_FRIEND.selectSearchDiaryList",pushChatDiary);
    }
}
